using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ICeFramework.Win.UI
{
    public partial class SeparationLine : UserControl
    {

        public enum Orientation { loHorizontal, loVertical };
        public enum Surface { lsRaised, lsLowered };

        private int FTickness = 2;
        private Orientation FlnO = Orientation.loHorizontal;
        private Surface FlnS = Surface.lsRaised;
        private Color FCol = Color.White;
        private Color SCol = Color.DarkGray;

        public int LineTickness
        {
            get
            {
                return FTickness;
            }
            set
            {
                if (value % 2 != 0)
                {
                    value = value - (Convert.ToInt32(value) % 2);
                }

                if (value >= 2)
                {
                    FTickness = value;
                }
                else FTickness = 2; 
                
                this.Refresh();
            }
        }

        public Orientation LineOrientation
        {
            get
            {
                return FlnO;
            }
            set
            {
                FlnO = value;
                ChangeLineOrientation();
                this.Refresh();
            }
        }

        public Surface LineSurface
        {
            get
            {
                return FlnS;
            }
            set
            {
                FlnS = value;
                this.Refresh();
            }
        }

        
        public Color FirstColor
        {
            get
            {
                return FCol;
            }
            set
            {
                FCol = value;
                this.Refresh();
            }
        }

        public Color SecondColor
        {
            get
            {
                return SCol;
            }
            set
            {
                SCol = value;
                this.Refresh();
            }
        }


        public SeparationLine()
        {
            InitializeComponent();
        }

        private void SeparationLine_Paint(object sender, PaintEventArgs e)
        {

            Graphics grp;
            Bitmap m_bmpBk = new Bitmap(ClientSize.Width, ClientSize.Height);
            grp = Graphics.FromImage(m_bmpBk);
            int tick = FTickness / 2;

            Pen p1 = new Pen(FCol);
            Pen p2 = new Pen(SCol);

            if (FlnO == Orientation.loHorizontal)
            {
                for (int i = 1; i <= tick; i++)
                {
                    if (FlnS == Surface.lsRaised)
                    {
                        grp.DrawLine(p1, new Point(0, i), new Point(this.ClientRectangle.Width, i));
                    }
                    else grp.DrawLine(p2, new Point(0, i), new Point(this.ClientRectangle.Width, i));
                }
                for (int i = tick + 1; i <= tick * 2; i++)
                {
                    if (FlnS == Surface.lsRaised)
                    {
                        grp.DrawLine(p2, new Point(0, i), new Point(this.ClientRectangle.Width, i));
                    }
                    else grp.DrawLine(p1, new Point(0, i), new Point(this.ClientRectangle.Width, i));
                }
            }
            else
            {
                for (int i = 1; i <= tick; i++)
                {
                    if (FlnS == Surface.lsRaised)
                    {
                        grp.DrawLine(p1, new Point(i, 0), new Point(i, this.ClientRectangle.Height));
                    }
                    else grp.DrawLine(p2, new Point(i, 0), new Point(i, this.ClientRectangle.Height));
                }
                for (int i = tick + 1; i <= tick * 2; i++)
                {
                    if (FlnS == Surface.lsRaised)
                    {
                        grp.DrawLine(p2, new Point(i, 0), new Point(i, this.ClientRectangle.Height));
                    }
                    else grp.DrawLine(p1, new Point(i, 0), new Point(i, this.ClientRectangle.Height));
                }

            }

            e.Graphics.DrawImage(m_bmpBk, 0, 0);
            m_bmpBk.Dispose();
        }

        private void ChangeLineOrientation()
        {
            if (FlnO == Orientation.loHorizontal && this.Size.Height>this.Size.Width)
            {
                base.Size = new Size(this.Size.Height, this.Size.Width);
            }

            if (FlnO == Orientation.loVertical && this.Size.Height < this.Size.Width)
            {
                base.Size = new Size(this.Size.Height, this.Size.Width);
            }
        }
    }
}
